package test;

import static org.junit.Assert.*;

import java.util.ArrayList;

import movement.Location;

import org.junit.Before;
import org.junit.Test;

import unit.Garage;
import unit.PoliceCar;
import unit.Unit;

import dispatch.*;
import emergency.*;


public class testDisaster {

	Emergency em2, em3,em4;
	DispatchCenter dc;
	Garage garage;
	ArrayList<Emergency> emergencies;
	Unit p1,p2,p3,p4;
	
	@Before
	public void setUp() throws Exception {
		dc = new DispatchCenter("DC1", new Location(0,0,"DC"), new Location(100,100,"GarageLoc"));
		em2 = new Robbery(new Location(50,50,"Robbery1"),Severity.SERIOUS,dc,false,false);
		em3 = new Robbery(new Location(250,250,"Robber2"),Severity.SERIOUS,dc,true,true);
		emergencies = new ArrayList<Emergency>();
		emergencies.add(em2);
		emergencies.add(em3);
		em4 = new Disaster(dc, emergencies, "Earthquake");
		p1 = new PoliceCar("P1", 100, dc.getGarage());
		p2 = new PoliceCar("P2", 110, dc.getGarage());
		p3 = new PoliceCar("P3", 90, dc.getGarage());
		p4 = new PoliceCar("P4", 120, dc.getGarage());
		
	}
	
	@Test
	public void testAllEmergenciesCompleted(){
		Disaster d = (Disaster) em4;
		assertFalse(d.allEmergenciesCompleted());
	}

	@Test
	public void testAssignAllUnits() throws IllegalAccessException{
		assertFalse(p1.isAssigned());
		assertFalse(p2.isAssigned());
		assertFalse(p3.isAssigned());
		assertFalse(p4.isAssigned());
		
		em4.assignAllUnits(dc.getGarage());
		
		assertTrue(p1.isAssigned());
		assertTrue(p2.isAssigned());
		assertTrue(p3.isAssigned());
		assertTrue(p4.isAssigned());
		assertEquals(em2, p1.getEmergency());
		assertEquals("stateinprogress", em2.getStateName());
		
		assertEquals(em3, p2.getEmergency());
		assertEquals(em3, p3.getEmergency());
		assertEquals(em3, p4.getEmergency());
		assertEquals("stateinprogress", em3.getStateName());
	}

	@Test
	public void testConstructorAndGetters() {
		assertEquals(Severity.SERIOUS,em4.getSeverity());
		assertEquals(150,em4.getLocation().getX());
		assertEquals(150,em4.getLocation().getY());
		assertEquals(emergencies.size(),em4.getEmergenciesClone().size());
		assertEquals(emergencies.get(0).getLocation(),em4.getEmergenciesClone().get(0).getLocation());
		assertEquals(emergencies.get(1).getLocation(),em4.getEmergenciesClone().get(1).getLocation());
		assertEquals("Earthquake", em4.getDescription());
		assertEquals(em4, emergencies.get(0).getDisaster());
		assertEquals(em4, emergencies.get(1).getDisaster());
	}
	
	// other methods to complex to test seperately -> total test are in the useCaseTests
	
}
